import axiosServer from '../request'
import type { IResponseData } from '../../utils/types'
// import { source } from '@/api/request'

/**
 * 上传大文件
 * @returns
 */
export const RequestUploadBigFile = (formData: FormData): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/bigfile',
		method: 'post',
		headers: { 'Content-Type': 'multipart/form-data' },
		data: formData,
		// signal:controller.signal,
		// cancelToken: source.token

		// `onUploadProgress` 允许为上传处理进度事件
		// onUploadProgress: function (progressEvent) {
		// 	callback(progressEvent)
		// }
	})
}

/**
 * 合并大文件
 * @returns
 */
export const RequestMergeBigFile = (chunkSize: number, fileName: string): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/mergefile',
		method: 'get',
		params: {
			chunkSize,
			fileName
		}
	})
}
/**
 * 检查大文件
 * @returns
 */
export const RequestCheckBigFile = (filename: string): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/checkfile',
		method: 'get',
		params: {
			filename
		}
	})
}

/**
 * 添加视频
 * @returns
 */
export const RequestAddVedio = (title: string, nick: string, url: string, uid: number): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/vedio',
		method: 'post',
		data: {
			title,
			nick,
			url,
			uid
		}
	})
}

/**
 * 上传大文件
 * @returns
 */
export const RequestVedioList = ({
	pageNo = 1,
	pageSize = 5,
	nick = '',
	startTime = '',
	endTime = ''
}): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/vedio',
		method: 'get',
		params: {
			pageNo,
			pageSize,
			nick,
			startTime,
			endTime
		}
	})
}

/**
 * 视频删除
 * @returns
 */
export const RequestVedioDeleteById = (id: number): Promise<IResponseData> => {
	return axiosServer({
		method: 'delete',
		url: '/api/song/vedio?id=' + id
	})
}

/* 添加音乐  */
export const RequestMusicAdd = (
	title: string,
	artist: string,
	picture: string,
	url: string,
	lyric: string
): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/add',
		method: 'post',
		data: {
			title,
			artist,
			picture,
			url,
			lyric
		}
	})
}

/* 
  音乐列表
*/
export const RequestMusicListPage = (pageNo: number, pageSize: number): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/list',
		method: 'get',
		params: {
			pageNo,
			pageSize
		}
	})
}

/**
 * 查询音乐
 * @param {} id
 */
export const RequestMusicFind = (sid: number): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/find',
		method: 'get',
		params: {
			sid
		}
	})
}

/**
 * 修改音乐
 */
export const RequestMusicUpdate = (
	sid: number,
	title: string,
	artist: string,
	picture: string,
	url: string,
	lyric: string
): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/update',
		method: 'post',
		data: {
			sid,
			title,
			artist,
			picture,
			url,
			lyric
		}
	})
}
/**
 * 删除音乐
 */
export const RequestMusicDelete = (sid: number): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/song/delete',
		method: 'get',
		params: {
			sid
		}
	})
}
